<?php
$service_code = "KNIPPEN";
?>

<div id="knippen_dialog" title="Laat je knippen op het werk bij Red Je Zaterdag">

  <?php 
  include 'common/body.error.inc.php';
  ?>
  
  <div id="datetime_picker_wrapper">

    <div id="datepicker_wrapper">
      
      <?php

      $sql = "";
      $sql .= "SELECT CODE, NAME ";
      $sql .= "FROM LOCATIONS ";
      $sql .= "WHERE COMPANY_CODE = '$company_code' ";
      $sql .= "ORDER BY CODE ASC ";
      //echo $sql;
      conn();
      $result = mysql_query($sql);
      if (!$result) {die('Could not exec query: ' . mysql_error());}
      $numRows = mysql_num_rows($result);
      close();
      ?>
      
      <?php if ($numRows > 1) { ?>
        <div class="title">
          Kies hier de locatie
        </div>
        <select id="knippen_location_code" name="location_code">
          <?php
          echo "<option value=\"\">Kies een locatie ..</option>";
          while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
            echo "<option value=\"".$row["CODE"]."\">".$row["NAME"]."</option>";
          }
          ?>
        </select>
      <?php } else if ($numRows == 0) { ?>
        <p>
          <span class="error">Er zijn geen locaties gevonden</span>
        </p>
      <?php } else { ?>
        <div class="title">
          De locatie
          <?php
          $row = mysql_fetch_array($result, MYSQL_ASSOC);
          echo "<span class=\"bg\">".$row["NAME"]."</span>";
          echo "<input type=\"hidden\" id=\"knippen_location_code\" name=\"location_code\" value=\"".$row["CODE"]."\" />";
          ?>
        </div>
        <script type="text/javascript">
        $(function(){
          loadKnippenDateTable();
        })
        </script>
      <?php } ?>
      
      <div id="knippen_date_table"></div>
      
      <?php

      $sql = "";
      $sql .= "SELECT DATE_FORMAT(R.START,'%d-%m-%Y') DATE_NL, DATE_FORMAT(R.START,'%H:%i') TIME_NL ";
      $sql .= "FROM RESERVATIONS R ";
      $sql .= "   INNER JOIN SCHEDULES S ON S.ID = R.SCHEDULE_ID ";
      $sql .= "WHERE UPPER(R.SIGN_IN_EMAIL) = UPPER('".mysql_escape($email)."') ";
      $sql .= "AND CAST(R.CONFIRMED AS unsigned int) = 1 ";
      $sql .= "AND S.SERVICE_CODE = '$service_code' ";
      $sql .= "ORDER BY R.ID DESC ";

      conn();
      $result = mysql_query($sql);
      if (!$result) {die('Could not exec query: ' . mysql_error());}
      $numRows = mysql_num_rows($result);
      close();
      ?>
      
      <div id="reservation_history_table" style="float: left; width: 300px">
      <?php if ($numRows > 0) { ?>
        <table>
          <tr>
            <td colspan="2"><h1>Dienst: <?php echo $service_code; ?></h1></td>
          </tr>
          <tr>
            <td colspan="2"><h1>Je laatste afspraken waren op:</h1></td>
          </tr>
          <tr>
            <td>datum</td>
            <td>tijd</td>
          </tr>
          <?php
          while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
            echo "<tr>";
            echo "<td>".$row["DATE_NL"]."</td>";
            echo "<td>".$row["TIME_NL"]."</td>";
            echo "</tr>";
          }
          ?>
        </table>
      <?php } ?>         
      </div>
    </div>  
      
    <div id="knippen_schedule_table"></div>
    
    <div class="clear"></div>
  
  </div>

  <div style="clear: both"></div>
  
  <hr />
  
  <p class="links">
    <a class="cancel" id="knippen_dialog_cancel" href="#">Annuleren</a>
  </p>
  
</div>      
